package com.code;

import com.code.impl.*;
import com.code.impl.base.BaseCodeWrite;
import com.common.config.ProjectConfig;
import com.common.entity.CClass;

import java.util.Arrays;
import java.util.List;


public class CodeWriteFactory {


    public void write(CClass cClass, CodeWriter[] codeWriters) {
        Arrays.stream(codeWriters).forEach(codeWriter -> codeWriter.write(cClass));
    }

    public static CodeWriter[] write(List<CClass> cClass, ProjectConfig projectConfig) {
        CodeWriter[] codeWriters = new CodeWriter[]{
                new EntryCodeWrite(projectConfig),
                new MapperCodeWrite(projectConfig),
                new ServiceCodeWrite(projectConfig),
                new ServiceImplCodeWrite(projectConfig),
                new ControllerCodeWrite(projectConfig),
                new XmlCodeWrite(projectConfig)
        };
        if (cClass == null) {
            return null;
        }
        new BaseCodeWrite(projectConfig).write();
        CodeWriteFactory codeWriteFactory = new CodeWriteFactory();
        for (CClass aClass : cClass) {
            codeWriteFactory.write(aClass, codeWriters);
        }
        return codeWriters;
    }
}
